<script type="text/javascript">

    // Function for reload Sub Departemen option, depend on selected Departemen
    var f_set_combo_sub_departemen = function(){
        var ls_departemen_code    = $('#id_departemen_fk').val();
        var ls_sub_departemen_code        = '<?php echo $data['id_sub_departemen_fk']; ?>';

        $('#id_sub_departemen_fk').setCombo({ 
            data: gs_path+'/hrd_karyawan/comboSubDepartemen/?id_departemen='+ls_departemen_code, 
            value: ls_sub_departemen_code 
        });
    };
    
    var f_set_combo_jurusan = function(){
        var ls_jenjang_code    = $('#id_jenjang_pendidikan_fk').val();
        var ls_jurusan_code        = '<?php echo $data['id_jurusan_pendidikan_fk']; ?>';

        $('#id_jurusan_pendidikan_fk').setCombo({ 
            data: gs_path+'/hrd_karyawan/comboJurusan/?id_jenjang='+ls_jenjang_code, 
            value: ls_jurusan_code 
        });
    };

    function buat_karyawan () {
        // loadPage('/hrd_karyawan/create'); 
        // loadPage('/hrd_karyawan/jadikan_karyawan/'+$('#id_pelamar_pk').getval()); 
        loadPage('/hrd_karyawan/jadikan_karyawan/?id_pelamar_pk='+$('#id_pelamar_pk').getval()); 
        // loadPage('/hrd_karyawan/edit/?id_karyawan_pk=AA'); 
        // loadPage(gs_path + '/hrd_karyawan/jadikan_karyawan/?id_pelamar_pk='+urlencode($('#id_pelamar_pk').getval()));
    }

    $(document).ready(function() {
        // Setup Form
        $('#form_master').setupForm([
            { name: 'id_pelamar_pk', type: 'text', size: 'medium', maxlength: 10, noempty:true },
            { name: 'nama_pelamar', type: 'text', size: 'medium', maxlength: 100, noempty:true },
            { name: 'ip', size:'medium', maxlength:4 },
            { name: 'gaji_harapan', type: 'numeric', size:'medium' },
            { name: 'status_lulus', size:'medium', data:[{ value:'', display:'' }, { value:'1', display:'lulus' }, { value:'0', display:'Tidak Lulus' }] },
            { name: 'id_jenjang_pendidikan_fk', size: 'medium', data:<?php echo json_encode(array_merge(array(array('value'=>'','display'=>'')),$listJenjang)); ?>, onChange:f_set_combo_jurusan },
            { name: 'id_jurusan_pendidikan_fk', size: 'medium', data:[] },
            { name: 'id_departemen_fk', size:'medium', data:<?php echo json_encode(array_merge(array(array('value'=>'','display'=>'')),$listDepartemen)); ?>, onChange:f_set_combo_sub_departemen },
            { name: 'id_sub_departemen_fk', size:'medium', data:[] },
            { name: 'tgl_lamaran', type:'date', size:'short' },
        ], 
            <?php echo json_encode($data); ?>
        );

        $('#ip').numberbox({
            min:0,
            precision:2
        });

        f_set_combo_sub_departemen();
        f_set_combo_jurusan();
        
        <?php if($mode=="edit"){ ?>
        $('#id_pelamar_pk').readonly();
        <?php } ?>
        
        // Set Action Button
        var buttons = [{ label: 'Save', icon: 'save', onclick: function() { 
                            $('#form_master').submitForm(   '/'+controller+'/ajax_post', 
                                {   
                                    onComplete : function(data){ eval('oData = '+data); loadPage('/'+controller+'/edit/?id_pelamar_pk='+(oData.genid!='' ? oData.genid : $('#id_pelamar_pk').getval())); }
                                } 
                            ); 
                        }},
                       { label: 'Close', icon: 'cancel', onclick: function() { loadPage('/'+controller+'/Index'); } }];
        setAction(buttons);
        
        // Create Tab
        $('#tt').tabs({ border:false });  
        
        // Focus at First Object
        $('#form_master').focusFirst();

        // Cek Status
        function cekStatusLulus(a) {
            if (a.toLowerCase() == 1) {
                $('#tombolKaryawan').attr("disabled", false);
            } else {
                $('#tombolKaryawan').attr("disabled", true);
            }
        }

        var a = $("#status_lulus option:selected").val();
        cekStatusLulus(a);
        // $( "#status_lulus" ).live( "click", function() {
        //     var a = $("#status_lulus option:selected").val();
        //     cekStatusLulus(a);
        // });
        
    });
</script>

<div id="form_master_message" style="display:none;"></div>
<table class="tb_form" style="display:none; width:100%; " cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td class="label">No Lamaran</td>
        <td><input id="id_pelamar_pk" /></td>
        <!-- <td colspan="2" rowspan="8">Foto : <img src="/primkokas/files/people.png" width="150" height="200" border="3" style="float:right;"> </td> -->
    </tr>
    <tr>
        <td class="label">Nama</td>
        <td><input id="nama_pelamar" /></td>
    </tr>
    <tr>
        <td class="label">Pendidikan Terakhir - Jurusan</td>
        <td><input id="id_jenjang_pendidikan_fk" /> _ <input id="id_jurusan_pendidikan_fk" /></td>
    </tr>
    <tr>
        <td class="label">Ip</td>
        <td><input id="ip" /></td>
    </tr>
    <tr>
        <td class="label">Status</td>
        <td><input id="status_lulus" /> <button id="tombolKaryawan" disabled onclick="buat_karyawan()">Jadikan Karyawan</button> </td>
    </tr>
    <tr>
        <td class="label">Tgl masuk lamaran</td>
        <td><input id="tgl_lamaran" /></td>
    </tr>
</table>


<fieldset style="width:600px;">
<legend><b>Menginginkan</b></legend>
<table class="tb_form" style="display:none; width:100%; " cellpadding="0" cellspacing="0" border="0">   
    <tr>
        <td class="label">Unit Kerja - Jabatan</td>
        <td><input id="id_departemen_fk" /> _ <input id="id_sub_departemen_fk" /></td>
    </tr>
    <tr>
        <td class="label">Gaji</td>
        <td><input id="gaji_harapan" /></td>
    </tr>
</table>
</fieldset>
<br><br>

<div id="tt" class="easyui-tabs" style="min-height:400px;"> 

    <div title="Personal Info" style="overflow:auto;padding:10px;">  
        <?php require_once('detail_personal.php'); ?>
    </div>

    <div title="Detail Pendidikan" style="overflow:auto;padding:10px;">  
        <?php if ($mode=="edit"): ?>
            <?php require_once('detail_pendidikan.php'); ?>
        <?php else: ?>
            <center><h4>Lakukan Save terlebih dahulu untuk memasukkan data Pendidikan!!</h4></center>
        <?php endif ?>
    </div>

    <div title="Pengalaman kerja" style="overflow:auto;padding:10px;">  
        <?php if ($mode=="edit"): ?>
            <?php require_once('detail_pengalaman_kerja.php'); ?>
        <?php else: ?>
            <center><h4>Lakukan Save terlebih dahulu untuk memasukkan data Pengalaman Kerja!!</h4></center>
        <?php endif ?>
    </div>

    <div title="Kemampuan" style="overflow:auto;padding:10px;">  
        <?php if ($mode=="edit"): ?>
            <?php require_once('detail_kemampuan.php'); ?>
        <?php else: ?>
            <center><h4>Lakukan Save terlebih dahulu untuk memasukkan data Pendidikan!!</h4></center>
        <?php endif ?>
    </div>

    <div title="Pelatihan" style="overflow:auto;padding:10px;">  
        <?php if ($mode=="edit"): ?>
            <?php require_once('detail_pelatihan.php'); ?>
        <?php else: ?>
            <center><h4>Lakukan Save terlebih dahulu untuk memasukkan data Pendidikan!!</h4></center>
        <?php endif ?>
    </div>

    <div title="Hasil Tes" style="overflow:auto;padding:10px;"> 
        <?php if ($mode=="edit"): ?>
            <?php require_once('detail_hasil_tes.php'); ?>
        <?php else: ?>
            <center><h4>Lakukan Save terlebih dahulu untuk memasukkan data Hasil Tes!!</h4></center>
        <?php endif ?> 
    </div>

</div>